package tripController;

import java.util.List;

import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Page;

import jfinalUtil.OtherUtil;
import tripModel.Location;
import tripModel.Total;
import tripService.CityService;
import tripService.LocationService;
import tripService.NoteService;
import tripService.TotalService;

public class TripController extends Controller {
	public void index() {
		List<Total> totalList = TotalService.showTotal();
		List<Location> locationList = LocationService.findLocationByTop();
		setAttr("locationList", locationList);// 轮播景点按创建时间排列
		setAttr("totalList", totalList);// 主题
		setAttr("locationTopList", LocationService.findLocationByCreateDateToTop());
		setAttr("hotCityList", CityService.findCityToHot());
		setAttr("AllProvinceList", CityService.findAllProvince());
		setAttr("CityForFirstProvinceList", CityService.findCityForFirstProvince());
		setAttr("LocationByFirstProvinceList", LocationService.findLocationByFirstProvince());
		super.render("main.jsp");
	}

	public void showLocationByTotal() {
		List<Total> totalList = TotalService.showTotal();
		Long tID = getParaToLong(0);
		String str = getPara(1);
		String tName = OtherUtil.codingToUTF8(str);
		int pageNumber = getParaToInt(2, 1);
		Page<Location> page = LocationService.findLocationByTotal(tID, pageNumber);
		setAttr("tID", tID);
		setAttr("tName", tName);
		setAttr("page", page);
		setAttr("totalList", totalList);
		render("showByTotal.jsp");
	}

	public void showhot() {

		int pageNumber = getParaToInt(0, 1);
		Page<Location> page = LocationService.showhot(pageNumber);
		List<Location> list = LocationService.showtop();
		setAttr("list", list);
		setAttr("page", page);
		render("hotshow.jsp");
	}

	public void showCity() {
		Long id = getParaToLong("id");
		renderJson(CityService.findCityByProcince(id));
	}

	public void showLocation() {
		Long id = getParaToLong("id");
		renderJson(LocationService.findLocationByID(id));
	}

	public void showLocationByLid() {
		Long lID = getParaToLong(0);
		setAttr("totalList", TotalService.showTotal());// 主题
		setAttr("Location", LocationService.findLocationByLid(lID));// 景点信息
		render("showLocation.jsp");
	}

	public void ShowNotesByLID() {
		Long lID = getParaToLong(0);
		setAttr("totalList", TotalService.showTotal());// 主题
		setAttr("notesList", NoteService.findNotesByLID(lID));// 游记信息
		render("showNotes.jsp");
	}

	public void showNoteByNid() {
		Long nID = getParaToLong(0);
		setAttr("totalList", TotalService.showTotal());// 主题
		setAttr("note", NoteService.findNoteByNid(nID));
		render("showNote.jsp");
	}

	public void showLocationByMoods() {
		int pageNumber = getParaToInt(0, 1);
		setAttr("page", LocationService.findLocationByMoods(pageNumber));
		render("showLocationByMoods.jsp");
	}

	public void showNotes() {
		int pageNumber = getParaToInt(0, 1);
		setAttr("totalList", TotalService.showTotal());// 主题
		setAttr("notePage", NoteService.getNotes(pageNumber));
		render("showAllNotes.jsp");
	}
}
